package top.ivansong92.example.leetcode.learning.data.struct.array.sort;

/**
 * 插入排序
 */
public class InsertSort implements ArraySort {
    @Override
    public void sort(int[] array) {
        if (array == null || array.length < 2) {
            return;
        }

        for (int i = 1; i < array.length; i++) {
            int val = array[i];
            int index = i - 1;
            while (index >= 0 && array[index] > val) {
                array[index + 1] = array[index];
                index--;
            }
            array[index + 1] = val;
        }


    }

}
